<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActionController::Routing::Optimisation::PositionalArguments</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActionController::Routing::Optimisation::PositionalArguments</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/actionpack/lib/action_controller/routing/optimisations_rb.html">
                vendor/rails/actionpack/lib/action_controller/routing/optimisations.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Optimiser.html">
                Optimiser
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Given a route
</p>
<pre>
  map.person '/people/:id'
</pre>
<p>
If the user calls <tt>person_url(@person)</tt>, we can simply return a
string like &quot;/people/#{@person.to_param}&quot; rather than triggering
the expensive logic in <tt>url_for</tt>.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000970">generation_code</a>&nbsp;&nbsp;
      <a href="#M000969">guard_conditions</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000970" class="method-detail">
        <a name="M000970"></a>

        <div class="method-heading">
          <a href="#M000970" class="method-signature">
          <span class="method-name">generation_code</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000970-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000970-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/routing/optimisations.rb, line 78</span>
 78:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generation_code</span>
 79:           <span class="ruby-identifier">elements</span> = []
 80:           <span class="ruby-identifier">idx</span> = <span class="ruby-value">0</span>
 81: 
 82:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">kind</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:url</span>
 83:             <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'#{request.protocol}'</span>
 84:             <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'#{request.host_with_port}'</span>
 85:           <span class="ruby-keyword kw">end</span>
 86: 
 87:           <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'#{ActionController::Base.relative_url_root if ActionController::Base.relative_url_root}'</span>
 88: 
 89:           <span class="ruby-comment cmt"># The last entry in &lt;tt&gt;route.segments&lt;/tt&gt; appears to *always* be a</span>
 90:           <span class="ruby-comment cmt"># 'divider segment' for '/' but we have assertions to ensure that</span>
 91:           <span class="ruby-comment cmt"># we don't include the trailing slashes, so skip them.</span>
 92:           (<span class="ruby-identifier">route</span>.<span class="ruby-identifier">segments</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">segments</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">segments</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">segment</span><span class="ruby-operator">|</span>
 93:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">segment</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">DynamicSegment</span>)
 94:               <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">segment</span>.<span class="ruby-identifier">interpolation_chunk</span>(<span class="ruby-node">&quot;args[#{idx}].to_param&quot;</span>)
 95:               <span class="ruby-identifier">idx</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
 96:             <span class="ruby-keyword kw">else</span>
 97:               <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">segment</span>.<span class="ruby-identifier">interpolation_chunk</span>
 98:             <span class="ruby-keyword kw">end</span>
 99:           <span class="ruby-keyword kw">end</span>
100:           <span class="ruby-node">%(&quot;#{elements * ''}&quot;)</span>
101:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000969" class="method-detail">
        <a name="M000969"></a>

        <div class="method-heading">
          <a href="#M000969" class="method-signature">
          <span class="method-name">guard_conditions</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000969-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000969-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/routing/optimisations.rb, line 67</span>
67:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">guard_conditions</span>
68:           <span class="ruby-identifier">number_of_arguments</span> = <span class="ruby-identifier">route</span>.<span class="ruby-identifier">segment_keys</span>.<span class="ruby-identifier">size</span>
69:           <span class="ruby-comment cmt"># if they're using foo_url(:id=&gt;2) it's one</span>
70:           <span class="ruby-comment cmt"># argument, but we don't want to generate /foos/id2</span>
71:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">number_of_arguments</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
72:             [<span class="ruby-value str">&quot;args.size == 1&quot;</span>, <span class="ruby-value str">&quot;!args.first.is_a?(Hash)&quot;</span>]
73:           <span class="ruby-keyword kw">else</span>
74:             [<span class="ruby-node">&quot;args.size == #{number_of_arguments}&quot;</span>]
75:           <span class="ruby-keyword kw">end</span>
76:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>